package com.spirngcloud.alibabasentinelratelimiting.controller.mq.util.headersExchangeStrategy;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @version V1.0
 * @Author 宋聚智
 * @Date 2019/10/24 11:20
 * @description
 * @Modify By：
 * @ModifyTime： 2019/10/24
 * @Modify marker：
 **/
//headers路由策略的交换机注入
@Configuration
public class HeadersExchangConfig {
    @Bean(name = "myHeadersExchange")
    HeadersExchange getDirectExchange() {
        return new HeadersExchange("My-Headers-Exchange");
    }

    @Bean
    Binding bindingQueueOneToHeadersAllExchange(@Qualifier("myFirstQueue") Queue myFirstQueue,
                                                @Qualifier("myHeadersExchange") HeadersExchange myHeaderExchange) {
        Map<String,Object> headers= new HashMap<>();
        headers.put("name","admin");
        headers.put("motto","js");
        return BindingBuilder.bind(myFirstQueue).to(myHeaderExchange).whereAll(headers).match();
    }
    @Bean
    Binding bindingQueueOneToHeadersAnyExchange(@Qualifier("myThreeQueue") Queue myThreeQueue,
                                                @Qualifier("myHeadersExchange") HeadersExchange myHeaderExchange) {
        Map<String,Object> headers= new HashMap<>();
        headers.put("name","admin");
        headers.put("motto","js");
        return BindingBuilder.bind(myThreeQueue).to(myHeaderExchange).whereAny(headers).match();
    }
}
